package net.jxtz.jxtzos.controller.excption;


import net.jxtz.jxtzos.entity.web.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

@RestController
@ControllerAdvice
public class BaseExceptionController {

    /**
     * 数据库异常捕获
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = SQLIntegrityConstraintViolationException.class)
    public R errorHandler(SQLIntegrityConstraintViolationException ex) {
        ex.printStackTrace();
        return R.error().code(50010).message("数据异常，请重新添加 --> 可能是添加了不可重复的数据？");
    }

}
